package com.xiyue.lenovo.otheractivity;

import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.widget.Button;
import android.widget.Toast;

import java.util.List;

/**
 * Created by Lenovo on 2016/4/28.
 */
public class PreferenceActivityTest extends PreferenceActivity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //该方法用于为界面设置一个标题按钮
        if(hasHeaders()){
            Button button = new Button(this);
            button.setText("设置操作");
            //将该按钮添加到该界面上
            setListFooter(button);
        }
    }
    //重写该方法，负责加载界面布局文件
    @Override
    public void onBuildHeaders(List<Header> target) {
        //加载选项设置列表的布局文件
        loadHeadersFromResource(R.xml.preference_headers,target);
    }
    //重写该方法，验证PreferenceFragment是否有效

    @Override
    protected boolean isValidFragment(String fragmentName) {
        return true;
    }
    public static  class  PrefslFragment extends PreferenceFragment{
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.xml.preferences);
        }
    }
    public  static  class  Prefs2Fragment extends PreferenceFragment{
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.xml.display_prefs);
            //获取传入该Fragment的参数
            String website = getArguments().getString("website");
            Toast.makeText(getActivity(),"网站域名是"+website,Toast.LENGTH_LONG).show();

        }
    }
}
